function love.load()
	require "client" -- include the client side library
	require "cfg"
	chatlist={ } -- this is will out chat log table
	k_string="" -- our stored keyboard string, to see what we are typing
	net.action("chat",function(data) onchat(data) end) -- all actions pass a data variable when received by the client, so bind a function to call our onchat() command with the data whenever we get a chat
	if not net.connect(host,6113) then error("could not connect to host.") end
	net.lostconnect(function(err) -- bind a function to net.lostconnect() so if we lose connection, it throws an error.
		error("connection failed!")
	end )
	net.action("setname",name) -- send the server a message containing our username first thing so it isn't confused
	net.action("disconnect",function(data) -- bind a function for when our server tells us someone left
	-- wait until you have read the onchat() function to read this
	if #chatlist >15 then
		table.remove(chatlist,1)
	end
	chatlist[#chatlist+1]=data.. " has disconnected."
	end )
	love.graphics.setMode(320,240,false,true,0) -- give our user a very small window
end
function love.update(dt)
	net.process() -- update our data every frame, this can be set on a timer to decrease cpu usage, but this isn't that intensive
end
function shift() -- a handy little function we will use to see if the shift key is down
	if love.keyboard.isDown("lshift") or love.keyboard.isDown("rshift") then
		return true
	else return false end
end
function love.keypressed(key) -- our keyboard string functions, and some chat commands
	if key:len()==1 then -- this block is useless, it's just a long way to let people use special characters
		if shift() then
			if key=="1" then
				k_string=k_string.."!"
			end
			if key=="2" then
				k_string=k_string.."@"
			end
			if key=="3" then
				k_string=k_string.."#"
			end
			if key=="4" then
				k_string=k_string.."$"
			end
			if key=="5" then
				k_string=k_string.."%"
			end
			if key=="6" then
				k_string=k_string.."^"
			end
			if key=="7" then
				k_string=k_string.."&"
			end
			if key=="8" then
				k_string=k_string.."*"
			end
			if key=="9" then
				k_string=k_string.."("
			end
			if key=="0" then
				k_string=k_string..")"
			end
			if key:match("(%a)") then
				k_string=k_string..key:upper()
			end
			return
		end
		if key:match("(%d)") then 
			k_string=k_string..key
		end
		if key:match("(%a)") or key==" " then
			k_string=k_string..key
		end
	end
	if key=="backspace" then k_string=k_string:sub(1,k_string:len()-1) end -- let users backspace by removing a character off the top of the keyboard string
	if key=="return" then 
		sendchat(k_string) -- call function sendchat(), which is where we will.. send the chat.
		k_string="" -- give the user a blank slate to type off of
	end
	if key=="escape" then
		love.event.push("quit") -- let the user close the game with esc
	end
end
function sendchat(chat) -- where we send our chats
	net.action("chat",chat) -- call the action named "chat" in the server, and pass to it our parameter.
end
function onchat(chatinfo) -- when we receive chats
	sender,nchat=chatinfo:match("^([^%s%-%>%<]+)%s(.*)") -- use string.match() to separate the username and the message in our variable
	-- our variable will be formatted as:   <username> message that i am sending
	-- see server for more details on how the message is relayed
	if #chatlist >15 then -- if our chat list is too long..
		table.remove(chatlist,1) -- delete the oldest chat to make room for more
	end
	chatlist[#chatlist+1]=sender.." -> "..nchat -- add our received chat to the list!
end
function love.draw()
	for k,v in pairs(chatlist) do -- draw our chat log, using a simple for loop
		love.graphics.setColor(255,255,255,255)
		love.graphics.print(v,0,k*12)
	end
	love.graphics.setColor(60,60,60,120)
	love.graphics.rectangle("fill",0,200,320,13) -- give the user a makeshift textbox
	love.graphics.setColor(170,170,170,255)
	love.graphics.print(k_string,0,200) -- show the user what they have currently typed in
end